package kfs.light.screen;

import java.awt.image.BufferedImage;

public class Color extends Thread {
	int red;
	int blue;
	int green;
	
	private BufferedImage image;
	
	public void run(){
			if(image!=null){
				int height = image.getHeight();
				int width = image.getWidth();
				int count = 0;
				for (int x = 0; x < width; x++) {
					for (int y = 0; y < height; y++) {
						int color = image.getRGB(x, y);
						red += (color >> 16) & 0xFF;
						green += (color >> 8) & 0xFF;
						blue += (color >> 0) & 0xFF;
						count++;
					}
				}
				red = red / count;
				green = green / count;
				blue = blue / count;
				//notifyAll();
			}
	}
	
	public void setImage(BufferedImage zoneImage){
		image=zoneImage;
	}
	
	public Color(BufferedImage image){
		this.image=image;
	}
	
	public Color(int red, int blue, int green){
		setRed(red);
		setBlue(blue);
		setGreen(green);
	}

	public int getRed() {
		return red;
	}

	public void setRed(int red) {
		this.red = red;
	}

	public int getBlue() {
		return blue;
	}

	public void setBlue(int blue) {
		this.blue = blue;
	}

	public int getGreen() {
		return green;
	}

	public void setGreen(int green) {
		this.green = green;
	}
}
